package com.wechat.weibo.controller;

import com.wechat.weibo.entity.User;
import com.wechat.weibo.service.CommentService;
import com.wechat.weibo.service.LoginService;
import com.wechat.weibo.service.WeiboService;
import com.wechat.weibo.util.ResultMap;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Api
@Controller
public class CommentController {
    @Autowired
    WeiboService weiboService;
    @Autowired
    LoginService loginService;
    @Autowired
    CommentService commentService;
//    发评论
    @ApiOperation(value = "在某微博下评论")
    @PostMapping("/postComment")
    @ResponseBody
    public ResultMap postComment(String selfID, Integer weibo_id, String content){
        if(selfID==null||content==null||weibo_id==null||weiboService.showSingle(selfID,weibo_id)==null)return ResultMap.wrong();
        User user=loginService.getUser(selfID);
        if(user==null)return ResultMap.wrong();
        commentService.postComment(user,weibo_id,content);
        return ResultMap.success(null);
    }
//    显示评论
    @ApiOperation(value = "获取某微博下的评论")
    @GetMapping("/showComment")
    @ResponseBody
    public ResultMap showComment(String selfID,Integer weibo_id){
        if(loginService.getUser(selfID)==null)
            return new ResultMap(200,"your havent login",commentService.showComment(selfID,weibo_id));
        return ResultMap.success(commentService.showComment(selfID,weibo_id));
    }
}
